#ifndef GADGET_H
#define GADGET_H
#include <QtWidgets>
#include <QDateTime>
#include <QSqlQuery>
#include <QSqlRecord>
#include <QIODevice>
#include "solar/beacon/Field.h"


typedef enum{
    data_msec,
    data_sec,
    data_minute,
    data_hour,
    data_day,
    data_month,
    data_letter
} Leave;

typedef enum{
    Absolute,
    AdjustMent
}dbCstrMD;

typedef enum{
    cd_Ascii,
    cd_String
}cvType;

class Extend{

public:

    Extend(){srand((unsigned)time(NULL));};

    static QList<QString> AlphaArray(){
        QList<QString> AlphaArray;
        for(char i = 'A'; i < 'Z'; i++)
        {
            std::string str;
            str.push_back(i);
            AlphaArray.append(str.data());
        }
        return AlphaArray;
    }

    static QList<QString> CombinationColumn(QVariant attribute, QVariant destination);

    static void ColExtendToMapInt(QMap<int, QString> &Object, int bring);

    static void ColExtendToMapStr(QMap<QString, int> &Object, int bring);

    static void ColExtendToList(QStringList &Object, int bring);

    static QMap<QString, QList<QString>> SuperQuery(QSqlDatabase* db, QString tabname, QString fillQuery=NULL);

    static bool BoolAssert(QString _bool);

    static QStringList getGlobalMatching(QString sourceStr, QString regexp);

    static QStringList getGlobalMatching(QString sourceStr, QRegularExpression regexp);

    static QMap<QString, QString> getGlobalMatchingSec(QString sourceStr, QString regexp, uint skewing=0);

    static QMap<QString, QString> getGlobalMatchingSec(QString sourceStr, QString regexp, QString skewing);

    static QStringList ExtractPath(QString LongChar, QString primaryReg, QString secondaryReg, QStringList FilterObj = {});

    qint64 Getrandom(qint64 min, qint64 max);

    static qint64 Min(QList<qint64> _T);

    static qint64 Min(QList<int> _T);

    static qint64 Max(QList<qint64> _T);

    static qint64 Max(QList<int> _T);

    static QVariant Min(QList<QString> _T, bool isSizeMode=true);

    static QVariant Max(QList<QString> _T, bool isSizeMode=true);

    static void orderBy(QList<qint64> &_sc, bool reverse=false);

    static void orderBy(QList<int> &_sc, bool reverse=false);

    static std::string dbCstr(double cs, dbCstrMD mode=dbCstrMD::Absolute, int retain=2);

    static QStringList canonicalPath(QStringList Source, QStringList Suffixs = QStringList());

    static QString c_tuple(QList<QString> Arg);

    static QString c_tuple(QList<int> Arg);

    static QString c_tuple(QList<bool> Arg);

    static QMap<QString, QString> QssAttributeForMap(QString Qss, QString PrimaryAttri, QString ValueFilter=NULL);

    static QString QssAttributeValueSwap(QString Qss, QStringList PrimaryAttri, QList<QList<QString>> ChildKeys, QList<QList<QString>> ReplaceValues={});

    static QString QssAttributeValueSwap(QString Qss, QStringList PrimaryAttri, QString ChildKeys, QString ReplaceValues={});

    static QString QssAttributeValueSwap(QString Qss, QString PrimaryAttri, QStringList ChildKeys, QStringList ReplaceValues={});

    static QString g_plyduration(QVariant time);

    QString SuperConver(QString itsr, cvType Type, char spc=' ');

    static void wcormbc(wchar_t *w_char, char *_mbchar, bool reverser);

    static void wcormbc(wchar_t *w_char, const char *_mbchar);

    static void wcormbc(const wchar_t *w_char, char *_mbchar);

    static QByteArray getImgbyte(QVariant push);

    QString rectInfoProduction(char L_wall, char T_wall, char R_wall, char B_wall, char emptyFill, int L_tab, QStringList &content, QFont &contentFont);

    static bool isInt(QString _s);

    static QList<bool> isBoolli(QStringList li);

    static QList<QString> isStrli(QList<qint64> li);

    static QList<QString> isStrli(QList<bool> li);

    static QList<int> isIntli(QList<QString> li);

    static QString _date_time(Leave leave, QString problem=NULL);

    static QString join(QList<QString> &list, QString softshell="%1", QString specing=" ");

    static void getMatchingItem(QRegularExpression expr, QString _targrt, QString &_receive, int expectIndex=0);

    static void getMatchingItem(QList<QString> exprList, QString _targrt, QString &_receive, QList<int> expectIndex={0});

    static int lineDistance(QPoint &point1, QPoint &point2);

    static QPair<int, int> parallelx(QPoint &point1, int &point2_y, int radius);

    static QPair<int, int> parallely(QPoint &point1, int &point2_x, int radius);

    static void batchFont(QList<QWidget*> source, QFont &font, uint psize);

    static void batchFont(QList<QWidget*> source, QFont &font, QString family);

    static void batchFont(QList<QWidget*> source, QFont &font, QFont swap);

    static QVariant regeditVist(HKEY mstream, QString Pkey, QString Ckey);

    static bool startProcess(QString shellchar);

    template<typename _T, typename _P>
    static bool compareList(_T itertor, _P target){
        bool compare = false;
        int count = 0;
        if (itertor.size() == target.size())
        {
            foreach(QAction *iter, itertor)
            {
                foreach(QAction *targ, target)
                {
                    if (iter->text() == targ->text())
                    {
                        count++;
                    }
                }
            }
            if (itertor.size() == count) compare = true;
        }
        return compare;
    }

    static bool pcheck(QVariant path){
        QString strpath = path.toString();
        if ((QRegularExpression("[a-zA-Z]\\s*:\\s*[\\|/]").match(strpath).hasMatch() && !QFile(strpath).exists()) ||
             strpath.isEmpty())
        {
             return false;
        }
        return true;
    }

    static QList<int> pcheck(QList<QString> paths){
        QList<int> indexs;
        for(int index = 0; index < paths.size(); index++)
        {
            if (!pcheck(paths[index])) indexs.append(index);
        }
        return indexs;
    }

    static QList<int> pcheck(QList<QVariant> paths){
        QList<int> indexs;
        for(int index = 0; index < paths.size(); index++)
        {
            if (!pcheck(paths[index])) indexs.append(index);
        }
        return indexs;
    }

    static void painterLinear(QPainter &painter, QRect offectrect, NT::CST_BRIGHT_SPOT orien, QList<QColor> _colors);

    static qint64 g_pix_fl(QVariant pixmap, QSize expsize = QSize(60,60));

private:
    static QString QssAttributeValueSwapBase(QString Qss, QString PrimaryAttri, QStringList ChildKeys, QStringList ReplaceValues={});

};
#endif



